package com.example.samplelistener;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.widget.SeekBar;

public class SampleDialog extends Dialog {

    public interface OnWidthChangedListener {
        void widthChanged(int width);
    }
    private OnWidthChangedListener onWidthListener;

	public void setOnWidthListener(
			OnWidthChangedListener onWidthListener) {
		this.onWidthListener = onWidthListener;
	}

	public SampleDialog(Context context, boolean cancelable,
			OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
	}

	public SampleDialog(Context context, int theme) {
		super(context, theme);
	}

	public SampleDialog(Context context) {
		super(context);
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.contents_dialog);

		SeekBar bar = (SeekBar)this.findViewById(R.id.seekBar);
		bar.setOnSeekBarChangeListener(new SeekBarListener());
	}
	
	public class SeekBarListener implements SeekBar.OnSeekBarChangeListener {

		@Override
		public void onProgressChanged(SeekBar seekBar, int progress,
				boolean fromUser) {
		}

		@Override
		public void onStartTrackingTouch(SeekBar seekBar) {
		}

		@Override
		public void onStopTrackingTouch(SeekBar seekBar) {
			if (onWidthListener != null) {
				onWidthListener.widthChanged(seekBar.getProgress());
			}
			dismiss();
		}
	}
}
